/*
 * ad_test.cpp
 * This file is part of dynad
 *
 * Copyright (C) 2014 - Sebastian Gesemann
 *
 * dynad is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * dynad is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with dynad. If not, see <http://www.gnu.org/licenses/>.
 */


#include <iostream>
#include <utility>
#include "ad.hpp"

using std::cout;
using std::endl;

std::ostream& operator<<(std::ostream& out, advar const& x)
{
	out << x.value;
	char tmp[] = " d/d_:";
	for (auto&& d : x.derivs) {
		tmp[4] = d.first;
		out << tmp << d.second;
	}
	return out;
}

#define STRINGIFY_(x) #x
#define STRINGIFY(x) STRINGIFY_(x)

#define EXPR(x) x*x+3*cos(x)

int main()
{
	advar x = adiff(2,'x');
	cout << "With x = " << value_of(x) << ", ";
	advar y = EXPR(x);
	cout << STRINGIFY(EXPR(x)) << " = " << y << endl;
}

